﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using DomainModel.Entities;
using System.Web.Mvc;
using System.Web.Routing;
namespace WebUI.Helpers
{
    public static class PictureHelper
    {    
       

        public static string ShowPicture(this HtmlHelper helper, Picture picture, object htmlAttributes)
        {
            TagBuilder builder = new TagBuilder("img");
            string url = "/Content/images/no-image.jpg";

            if (picture != null && picture.PictureId > 0)
            {
                url = "/Content/Pictures/" + picture.Name;
                builder.Attributes.Add("src", url);
                builder.Attributes.Add("id", picture.Name);
                builder.Attributes.Add("name", picture.Name);
                builder.Attributes.Add("alt", picture.Name);
            }
            else
            {
                builder.Attributes.Add("src", url);
                builder.Attributes.Add("id", "");
                builder.Attributes.Add("name", "");
                builder.Attributes.Add("alt", "");
            }


            builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            return builder.ToString(TagRenderMode.SelfClosing);
        }

    }
}
